import vue from "rollup-plugin-vue";
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";

const config = [
  // Vue 组件
  {
    input: "src/vue/UpdateNotifier.vue",
    output: {
      file: "dist/vue-update-notifier.js",
      format: "esm",
    },
    plugins: [
      vue(),
      resolve(),
      commonjs(),
      babel({ babelHelpers: "bundled", presets: ["@babel/preset-env"] }),
      terser(),
    ],
  },
  // React 组件
  {
  input: 'src/react/UpdateNotifier.jsx',
  output: {
    file: 'dist/react-update-notifier.js',
    format: 'esm',
    globals: {
      'react': 'React',
      'react-dom': 'ReactDOM'
    }
  },
  external: ['react', 'react-dom'], // 将 React 和 ReactDOM 设为外部依赖
  plugins: [
    resolve(),
    commonjs(),
    babel({ 
      babelHelpers: 'bundled', 
      presets: ['@babel/preset-env', '@babel/preset-react'] 
    }),
    terser()
  ]
},
  // 核心库
  {
    input: "src/core/updateNotifier.js",
    output: {
      file: "dist/update-notifier-core.js",
      format: "umd",
      name: "UpdateNotifier",
    },
    external: ['vue'], // 将vue视为外部依赖
    plugins: [
      resolve(),
      commonjs(),
      babel({ babelHelpers: "bundled", presets: ["@babel/preset-env"] }),
      terser(),
    ],
  },
];

export default config;
